package com.kx.smartdevice.mapper;

import com.kx.smartdevice.pojo.Area;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Set;

public interface AreaMapper {

    @Select("select zi.id id,zi.areaname areaname,fu.areaname parentname,zi.status status from areas zi left join areas fu on zi.parentid=fu.id")
    Set<Area> findAllArea();

    Set<Area> findAllAreaByPage(@Param("areaname") String areaname, @Param("status") int status);

    @Insert("insert into areas(areaname,parentid,status) values(#{areaname},#{parentid},#{status})")
    void addAreas(Area area);

    @Update("update areas set areaname=#{areaname},parentid=#{parentid},status=#{status} where id=#{id}")
    int updateArea(Area area);


    int deleteAreaByIds(@Param("ids") String[] ids);

    @Select("select a.* ,ap.areaname parentname from areas a left join areas ap on a.parentid=ap.id WHERE a.id =#{id}")
    Area getAreaById(Long id);


    @Select("select a.* ,ap.areaname parentname from areas a left join areas ap on a.parentid=ap.id WHERE a.parentid =#{id}")
    List<Area> getAreaByParentId(Long id);


    List<Area> getAllFirstParentAreas(int status);
}
